<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>基本资料</title>
  {include file="common/_require"}

  <script>
    var currentHeaderNavItem = 'User';
    var currentLeftNavItem = 'index';
  </script>
</head>

<body class="layui-layout-body">

  <div class="layui-layout layui-layout-admin">
    {include file="common/_header"}

    {include file="common/left_user"}

    <div class="layui-body">

      <div style="padding:15px">
        <div class="main-header">
          <span class="layui-breadcrumb">
            <a>首页</a>
            <a><cite>添加用户</cite></a>
          </span>
        </div>
        <div class="main-container">
          <div class="layui-row">
            <div class="layui-col-md6">
              <fieldset class="layui-elem-field">
                <legend>添加管理员</legend>
                <div class="layui-field-box">
                  <form action="{:url('User/update')}" method="POST" class="layui-form" lay-filter='*'>
                    <input type="hidden" name="id" value="{$user.id}">
                    <div class="layui-form-item">
                      <div class="layui-form-label">登录账号</div>
                      <div class="layui-input-block">
                        <input type="text" name="account" required lay-verify="required" value="{$user.account}"
                          class="layui-input">
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-form-label">昵称</div>
                      <div class="layui-input-block">
                        <input type="text" name="nickname" required lay-verify="required" value="{$user.nickname}"
                          class="layui-input">
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-form-label">密码</div>
                      <div class="layui-input-block">
                        <input type="password" name="password" value="" class="layui-input">
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <label class="layui-form-label">账号类型</label>
                      <div class="layui-input-block">
                        {volist name=':app\model\User::$typeName' id='type'}
                        <input type="radio" name="type" value="{$key}" title="{$type}">
                        {/volist}
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <div class="layui-form-label">头像</div>
                      <div class="layui-input-block">
                        <div>
                          <div class="layui-btn upload-admin-avatar">上传</div>
                        </div>
                        <div>
                          <img class="layui-circle admin-avatar" style="width: 80px" src="{$user.avatar}"
                            alt="{$user.avatar}" srcset="">
                        </div>
                        <input type="hidden" name="avatar" value="{$user->getData('avatar')}" class="layui-input">
                      </div>
                    </div>
                    <div class="layui-form-item">
                      <button class="layui-btn layui-btn-fluid" type="submit">修改</button>
                    </div>
                  </form>
                </div>
              </fieldset>
            </div>
          </div>
        </div>
      </div>
    </div>


    {include file="common/_footer"}

    <script>
      layui.config({
        base: '/static/lib/layui/lib/cropper/'
      }).use(['layer', 'upload', 'croppers', 'form'], function () {
        var upload = layui.upload;
        var croppers = layui.croppers;
        var form = layui.form;

        form.val('*',{
          type:'{$user.type}'
        })

        var uploadSiteLogo = croppers.render({
          elem: '.upload-admin-avatar',
          url: '{:url("File/save")}',
          data: {
            type: 3,
            dir: 'user_avatar'
          },
          saveW: 200, //保存宽度

          saveH: 200,
          mark: 1 / 1, //选取比例

          area: true, //弹窗宽度

          accept: 'images',
          done: function (result) {
            if (result.code == 0) {
              layer.msg('上传成功');
              $('input[name="avatar"]').val(result.data.save_name);
              $('.admin-avatar').attr('src', result.data.src);
            } else {
              layer.msg(result.msg)
            }
          }
        })

      })
    </script>
  </div>
</body>

</html>